<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
<title>title</title>
<link rel="stylesheet" href="../assets/agile/css/ratchet/css/ratchet.min.css">
<link rel="stylesheet" href="../assets/agile/css/flat/flat.component.css">
<link rel="stylesheet" href="../assets/agile/css/flat/flat.color.css">
<link rel="stylesheet" href="../assets/agile/css/flat/iconline.css">
<link rel="stylesheet" href="../assets/app/css/app.css" />
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery.js"></script>
<script type="text/javascript" src="../script/config.js"></script>
<script type="text/javascript" src="../script/local.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<style type="text/css">
.user-listitem-line a{width:20px;height:20px;display:inline-block;float:right;}
.listitem li{background:#fbfbfb;padding:10px 0px 0px 12px;}
.listitem li .text i{vertical-align: sub;}.user-listitem-line p{display:inline-block;width:56%;}
.listitem li a{padding:12px 0;}
.user-head{background:#fbfbfb;}
</style>
</head>
<body>
<div id="ios-top-box">
	<div id="header" class="bar bar-nav">
	<div class="titlebar">
	<a href="javascript:appClose('address_list',api);"><i class="iconfont iconline-arrow-left"></i></a>
	<h1 class="title">收货地址</h1>
	<span class="iconfont iconline-refresh" style="position:absolute;right:5px;top:22px;"></span>
	</div>
	</div>
</div>
<section>
    <div class="create_goods">      
        <div class="clear"></div>
		<ul class="listitem user-listitem-line">
		</ul>
		<div class="clear"></div>
		<div class="block30"></div>
		<a href="javascript:randomSwitchBtn('add_address',api);" style="width:80%;margin:40px auto 0 auto;text-align:center;" class="aui-btn aui-btn-block aui-btn-success common-btn" id="btn_consignee_save" title="添加地址">添加新地址</a>
    </div>

</section>

</body>

<script type="text/javascript">
apiready = function(){
    var header = $api.byId('header');

    setInterval(function(){
    	if(localData.get('add_address_ok')){
    		window.location.reload();
    		localData.remove('add_address_ok');
    	}
    },1000);
       
$(function(){
    var userinfo = localData.get('userinfo');
	var userinfo = JSON.parse(userinfo);
	 if(userinfo != undefined && typeof userinfo == 'object' && userinfo != null){
		 
		 $('.iconline-refresh').click(function(){
			 window.location.reload();
		 });
		 
		 GetJPData(config.url+'/app.php?act=useraddress&uid='+userinfo.uid,{},function(data){
				if(data['status'] == 2){
					var html = '';
					for(var i=0; i < data['data'].length;i++){
						html += '<li item="'+data['data'][i]['id']+'"><a href="javascript:;">';
						html += '<i class="ricon iconfont"></i></a>';
						html += '<div class="text"><p class="hidetext" item="'+data['data'][i]['id']+'">'+ data['data'][i]['shi'] + data['data'][i]['xian'] + data['data'][i]['jiedao']+'</p>';
						var default_text = '';
						if(data['data'][i]['default'] == 'Y'){
							default_text += '<font class="default">默认&nbsp;&nbsp;&nbsp;</font>';
						}
						html += '<span style="float:right;">'+default_text+'<font class="update">修改</font>&nbsp;&nbsp;&nbsp;<font class="delete">删除</font></span></div></li>';
					}
					$('.listitem').append(html);
					$('.listitem').css({'height':'auto'});
					 
					 $('.delete').bind('click',function(){
					     var _thisLine = $(this).parents('li');
			             var id = parseInt($(this).parents('li').attr('item'));
			             if(!id) {
			                 $.PageDialog.fial('更新失败');
			                 return;
			             }
			        api.confirm({
			            title: '提示',
			            msg: '确定删除吗？',
			            buttons: ['确定', '取消']
			        },function( ret, err ){
			            if( ret['buttonIndex']==1 ){
			             GetJPData(config.url+'/app.php?act=deleteaddress&id='+id+'&uid='+userinfo['uid'],{},function(res){
			                 if(res['status'] == 1){
			                     _thisLine.remove();
			                     $.PageDialog.ok('<s></s>删除成功');
			                 }else{
			                     $.PageDialog.fail('删除失败');
			                 }
			             });
			            }else{
			                //
			            }
			        });

					 });
					 
			         $('.update').bind('click',function(){
			             var _thisLine = $(this).parents('li');
			             var id = parseInt($(this).parents('li').attr('item'));
			             if(!id) {
			                 return;
			             }
			             localData.set('address_id',id);
			             randomSwitchBtn('user_add',api);
			         });
					 
					 $('.listitem li p.hidetext').bind('click',function(){
						 var _this = $(this);
						 var id = parseInt($(this).attr('item'));
						 if(!id) {
							 $.PageDialog.fial('更新失败');
							 return;
						 }
						 
						 GetJPData(config.url+'/app.php?act=setaddressdefault&id='+id+'&uid='+userinfo['uid'],{},function(res){
							 if(res['status'] == 1){
								 $('.listitem font.default').remove();
								 _this.parent().find('span').find('.update').before('<font class="default">默认&nbsp;&nbsp;&nbsp;</font>');
							 }else{
								 $.PageDialog.fail('更新失败');
							 }
						 });
					 });
				}
		 });		 
	 }else{
		 randomSwitchBtn('login',api);
	 }
});
};

function op(tag,id){
	localData.set('address_id',id);
	randomSwitchBtn(tag,api);
}
</script>
</html>